package org.gap.jseed;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;

public class NoSuchInvocationHandlerError extends NoSuchFieldError {

	private static final long serialVersionUID = 4779912000896422527L;
	private final Exception wrappedException;

	public NoSuchInvocationHandlerError(String message, Exception wrappedException) {
		super(message);
		this.wrappedException = wrappedException;
	}
	
	@Override
	public Throwable getCause() {
		return wrappedException;
	}
	
	@Override
	public StackTraceElement[] getStackTrace() {
		ArrayList<StackTraceElement> result = new ArrayList<StackTraceElement>();
		Collections.addAll(result, super.getStackTrace());
		Collections.addAll(result, wrappedException.getStackTrace());
		return result.toArray(new StackTraceElement[result.size()]);
	}
	
	@Override
	public void printStackTrace(PrintWriter s) {
		super.printStackTrace(s);
		wrappedException.printStackTrace(s);
	}
}
